/*
 * FaceCat图形通讯框架
 * 著作权编号:2015SR229355+2020SR0266727
 * 上海卷卷猫信息技术有限公司
 */

using System;

namespace FaceCat {
    /// <summary>
    /// 月的按钮
    /// </summary>
    public class MonthButton {
        /// <summary>
        /// 创建月的按钮
        /// </summary>
        /// <param name="calendar">创建月的按钮</param>
        public MonthButton(FCCalendar calendar) {
            m_calendar = calendar;
        }

        public FCRect m_bounds;

        /// <summary>
        /// 获取显示区域
        /// </summary>
        public virtual FCRect getBounds()
        {
            return m_bounds;
        }

        /// <summary>
        /// 设置显示区域
        /// </summary>
        public virtual void setBounds(FCRect value)
        {
            m_bounds = value;
        }

        public FCCalendar m_calendar;

        /// <summary>
        /// 获取日历视图
        /// </summary>
        public virtual FCCalendar getCalendar()
        {
            return m_calendar;
        }

        /// <summary>
        /// 设置日历视图
        /// </summary>
        public virtual void setCalendar(FCCalendar value)
        {
            m_calendar = value;
        }

        public int m_month;

        /// <summary>
        /// 获取月
        /// </summary>
        public virtual int getMonth()
        {
            return m_month;
        }

        /// <summary>
        /// 设置月
        /// </summary>
        public virtual void setMonth(int value)
        {
            m_month = value;
        }

        public bool m_visible = true;

        /// <summary>
        /// 获取是否可见
        /// </summary>
        public virtual bool isVisible()
        {
            return m_visible;
        }

        /// <summary>
        /// 设置是否可见
        /// </summary>
        public virtual void setVisible(bool value)
        {
            m_visible = value;
        }

        public int m_year;

        /// <summary>
        /// 获取年
        /// </summary>
        public virtual int getYear()
        {
            return m_year;
        }

        /// <summary>
        /// 设置年
        /// </summary>
        public virtual void setYear(int value)
        {
            m_year = value;
        }

        public static String []m_monthStrs = new String[] { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};

        /// <summary>
        /// 获取月的文字
        /// </summary>
        /// <returns>月的文字</returns>
        public virtual String GetMonthStr() {
            if (m_month >= 1 && m_month <= 12)
            {
                return m_monthStrs[m_month - 1];
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 获取绘制的背景色
        /// </summary>
        /// <returns>背景色</returns>
        public virtual long getPaintingBackColor() {
            return FCColor.Back;
        }

        /// <summary>
        /// 获取绘制的边线颜色
        /// </summary>
        /// <returns>边线颜色</returns>
        public virtual long getPaintingBorderColor() {
            return FCColor.Border;
        }

        /// <summary>
        /// 获取要绘制的前景色
        /// </summary>
        /// <returns></returns>
        public virtual long getPaintingTextColor() {
            return FCColor.Text;
        }

        /// <summary>
        /// 触摸点击方法
        /// </summary>
        /// <param name="touchInfo">触摸信息</param>
        public virtual void onClick(FCTouchInfo touchInfo) {
            if (m_calendar != null) {
                CMonth month = m_calendar.getYears().getYear(m_calendar.getMonthDiv().getYear()).getMonths().get(m_month);
                m_calendar.setMode(FCCalendarMode.Day);
                m_calendar.setSelectedDay(month.getDays().get(1));
                m_calendar.update();
                m_calendar.invalidate();
            }
        }

        /// <summary>
        /// 重绘背景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintBackGround(FCPaint paint, FCRect clipRect) {
            long backColor = getPaintingBackColor();
            paint.fillRect(backColor, m_bounds);
        }

        /// <summary>
        /// 重绘边线方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintBorder(FCPaint paint, FCRect clipRect) {
            long borderColor = getPaintingBorderColor();
            paint.drawLine(borderColor, 1, 0, m_bounds.left, m_bounds.bottom - 1, m_bounds.right - 1, m_bounds.bottom - 1);
            paint.drawLine(borderColor, 1, 0, m_bounds.right - 1, m_bounds.top, m_bounds.right - 1, m_bounds.bottom - 1);
        }

        /// <summary>
        /// 重绘前景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintForeground(FCPaint paint, FCRect clipRect) {
            int width = m_bounds.right - m_bounds.left;
            int height = m_bounds.bottom - m_bounds.top;
            String monthStr = GetMonthStr();
            FCFont font = m_calendar.getFont();
            FCSize textSize = paint.textSize(monthStr, font, -1);
            //创建渐变刷
            FCRect tRect = new FCRect();
            tRect.left = m_bounds.left + (width - textSize.cx) / 2;
            tRect.top = m_bounds.top + (height - textSize.cy) / 2;
            tRect.right = tRect.left + textSize.cx;
            tRect.bottom = tRect.top + textSize.cy;
            paint.drawText(monthStr, getPaintingTextColor(), font, tRect, -1);
        }
    }
}
